package entity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;

import util.SecurityUtil;

@Entity
public class User implements Serializable{
	
	private static final long serialVersionUID = 1L;
	@Id
	@Column(name = "USERID", length = 50)
	private String userId = SecurityUtil.userIdGenerator().toString();
	@Column(name = "CAPASSWORD", length = 50, nullable=false)
	private String caPassword;
	@OneToMany(
		targetEntity=UserCheck.class, mappedBy = "ucid.user"
	)
	private List<UserCheck> userChecks = new ArrayList<UserCheck>();
	@OneToOne
	@JoinColumn(name="PASSPORTID")
	private Passport passport;
	
	public String getUserId() {
		return userId;
	}
	public void setUserId(String userId) {
		this.userId = userId;
	}
	public String getCaPassword() {
		return caPassword;
	}
	public void setCaPassword(String caPassword) {
		this.caPassword = caPassword;
	}
	public List<UserCheck> getUserChecks() {
		return userChecks;
	}
	public void setUserChecks(List<UserCheck> userChecks) {
		this.userChecks = userChecks;
	}
	public Passport getPassport() {
		return passport;
	}
	public void setPassport(Passport passport) {
		this.passport = passport;
	}
	public void addUserCheck(UserCheck uc){
		uc.getUcid().setUser(this);
		this.userChecks.add(uc);
	}
	public void removeUserCheck(UserCheck uc){
		uc.getUcid().setUser(null);
		this.userChecks.remove(uc);
	}
}
